import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import * as dto from './DTO';
import {formatMessage} from './intl';
const baseUrl = '/parts/api/v1';

const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询客户信息'
});

const getDetailDesc = formatMessage({
    id: 'api.message.getDetailDesc',
    defaultMessage: '查询客户信息详情'
});

const updateDesc = formatMessage({
    id: 'api.message.updateDesc',
    defaultMessage: '编辑客户信息管理'
});

const getPersonnelDesc = formatMessage({
    id: 'api.message.getPersonnelDesc',
    defaultMessage: '查询人员信息'
});

// 查询
export const getList = bodyCondition => {
    const queryString = stringify(bodyCondition);
    return request(`${baseUrl}/dealers?${queryString}`, null, dto.ListData)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};
// 查询详情
export const getDetail = id => request(`${baseUrl}/dealers/${id}`, null, dto.Detail)
    .then(handleFetchResultNotification(REQUEST_TYPE.query, getDetailDesc));

// 编辑
export const updateApplyReport = (id, data) => request(`${baseUrl}/dealers/${id}`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, updateDesc));

// 快捷查询人员清单
export const getPersonnels = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/Personnels/simple?${queryString}`, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getPersonnelDesc));
};
